package com.foreknow.protals.controller;

import com.foreknow.protals.common.api.CommonPage;
import com.foreknow.protals.common.api.CommonResult;
import com.foreknow.protals.dto.PmsProductCategoryDto;
import com.foreknow.protals.mbg.model.PmsProductCategory;
import com.foreknow.protals.service.PmsProductCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品分类管理Controller
 */
@Controller
@Api(tags = "PmsProductCategoryController",description = "商品分类管理")
@RequestMapping("/productCategory")
public class PmsProductCategoryController {

    @Autowired
    private PmsProductCategoryService productCategoryService;

    @ApiOperation("添加商品分类")
    @RequestMapping(value = "/create",method = RequestMethod.POST)
    @ResponseBody
    public CommonResult create(@RequestBody PmsProductCategoryDto productCategoryParam) {
       int count =  productCategoryService.create(productCategoryParam);
       if(count > 0) {
           return CommonResult.success(count);
       }else {
           return CommonResult.failed("null");
       }
    }

    @ApiOperation("修改商品分类")
    @RequestMapping(value = "/update/{id}",method = RequestMethod.POST)
    @ResponseBody
    public CommonResult update(@PathVariable Long id,@RequestBody PmsProductCategoryDto productCategoryParam) {
        int count = productCategoryService.update(id,productCategoryParam);
        if(count > 0) {
            return CommonResult.success(count);
        }else {
            return CommonResult.failed("");
        }
    }

}
